import time

from wxauto import *

from message.process import save_message
from message.question_count import update_image_dialog

# 获取当前微信客户端
wx = WeChat()


# 首先设置一个监听列表，列表元素为指定好友（或群聊）的昵称
listen_list = [
    '联空Agent测试'
]
# 然后调用`AddListenChat`方法添加监听对象，其中可选参数`savepic`为是否保存新消息图片
for i in listen_list:
    wx.AddListenChat(who=i, savepic=True)

while True:
    time.sleep(5)
    # 监听消息
    msgs = wx.GetListenMessage()

    for chat in msgs:
        # 获取消息内容
        one_msgs = msgs.get(chat)
        key = chat.who
        print(one_msgs)
        save_message(key,one_msgs)
        update_image_dialog()